package cn.mumzone.pos.presenter;

import cn.mumzone.basic.mvp.AbsPresenter;
import cn.mumzone.basic.net.http.callback.ApiCallBack;
import cn.mumzone.basic.net.response.BaseResponse;
import cn.mumzone.basic.util.StringUtils;
import cn.mumzone.pos.model.InventoryDetailEntity;
import cn.mumzone.pos.model.InventoryGoodsResult;
import cn.mumzone.pos.model.source.StockRepository;
import cn.mumzone.pos.presenter.contract.InventoryDetailContract;

/**
 * Created by qiuzhenhuan on 2019/10/11.
 */

public class InventoryDetailPresenter extends AbsPresenter<InventoryDetailContract.View, StockRepository>
        implements InventoryDetailContract.Presenter {


    @Override
    public void loadInventoryDetails(String orderId) {

        ApiCallBack<InventoryDetailEntity> callBack = new ApiCallBack<InventoryDetailEntity>() {
            @Override
            public void onSuccess(InventoryDetailEntity detailEntity) {
                mView.showInventoryDetails(detailEntity);
            }

            @Override
            public void onError(BaseResponse response) {
                mView.showError(response.getMsg());
            }
        };
        mRepo.getInventoryDetails(orderId, callBack);
        addSubscrebe(callBack);
    }

    @Override
    public void loadInventoryGoods(String orderId, final String keyword, final boolean isSearch) {
        ApiCallBack<InventoryGoodsResult> callBack = new ApiCallBack<InventoryGoodsResult>() {
            @Override
            public void onSuccess(InventoryGoodsResult detailEntity) {
                if (StringUtils.isEmpty(keyword)) {
                    mView.showInventoryGoods(detailEntity.getGoodsList());
                } else {
                    if (isSearch) {
                        mView.showSearchGoods(detailEntity.getGoodsList());
                    } else {
                        mView.showScanGoods(detailEntity.getGoodsList());
                    }
                }
            }

            @Override
            public void onError(BaseResponse response) {
                mView.showError(response.getMsg());
            }
        };
        mRepo.getInventoryGoodsList(orderId, keyword, callBack);
        addSubscrebe(callBack);
    }

    @Override
    public void doUpdateInventoryStatus(String orderId, String status) {
        ApiCallBack<Object> callBack = new ApiCallBack<Object>() {
            @Override
            public void onSuccess(Object detailEntity) {
                mView.showInventoryProgress();
            }

            @Override
            public void onError(BaseResponse response) {
                mView.showError(response.getMsg());
            }
        };
        mRepo.updateInventoryStatus(orderId, status, callBack);
        addSubscrebe(callBack);
    }
}
